<?php
/**
 * 友钱关于IDFA的上报接口
 * User: yaosj
 * Date: 15-12-2
 * Time: 上午11:11
 */

class IdfaReport implements iController {

    public function output($queryArgs) {

        if (empty($queryArgs['channel_id']) || empty($queryArgs['idfa']) || empty($queryArgs['app_id'])) {
            return json_encode(array('code' =>400,'error' => '参数错误','result' => ''));
        }
        $appId = trim($queryArgs['app_id']);

        global $uddb;
        $result = $uddb ->getRow('SELECT * FROM youqian_idfa_data WHERE idfa = :idfa AND app_id = :app_id AND `channel_id`="youqian"',
            array(':idfa' => trim($queryArgs['d']),
                  ':app_id' => $appId)
        );

        if (empty($result)) {
            $uddb -> insert('youqian_idfa_data',
                array(
                    'app_id' => $appId,
                    'channel_id' => trim($queryArgs['channel_id']),
                    'idfa' => trim($queryArgs['idfa']),
                    'mission_status' => 0,
                    'click_time' => date('Y-m-d H:i:s'),
                    'callback' => trim($queryArgs['callback'])
                )
            );

        } else  {
            if ($result -> mission_status == 1) {
                //存在这个设备，已经完成任务
                return json_encode(array('code' =>400,'error' => '已经完成任务','result' => ''));
            }
        }
        return json_encode(array('code' =>200,'error' => '','result' => ''));
    }
}